package com.spring.cloud.practice.demo.springbootrabbitmq.producer;

import com.spring.cloud.practice.demo.springbootrabbitmq.entity.Order;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.support.CorrelationData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * <b><code>TopicSender</code></b>
 * <p/>
 * Description
 * <p/>
 * <b>Creation Time:</b> 21-3-18 下午7:15.
 *
 * @author huanghuayan
 * @since spring-cloud-demo
 */
@Component
public class TopicSender {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void send(Long orderId) {
        Order order = Order.builder().id(orderId).build();
        System.out.println("order's Id :" + orderId);
        CorrelationData correlationData = new CorrelationData(order.getId().toString());

        rabbitTemplate.convertAndSend("order-topic-exchange", "order.queue", order, correlationData);

    }
}
